package edu.fsu.cs.SHPE;

import java.net.ConnectException;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class SessionActivity extends Activity {
	private static final String TAG = "SHPE.SessionActivity";
	
	private Session tmpSession;
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.session);
		setTitle("Session Information");
		
		SessionContainer session = null;
		
		try {
			session = new SessionContainer(Conference.insertId(getString(R.string.getSession), getIntent().getLongExtra("id", -1)));
		} catch (ConnectException e) {
			Toast.makeText(this, "Unable to Connect to Server", Toast.LENGTH_SHORT).show();
			e.printStackTrace();
		}
		
		if(session == null){
			Log.i(TAG, "Unable to get session");
			finish();
		}
		
		tmpSession = session.get(0);
		TextView tmp;
		
		Display display = getWindowManager().getDefaultDisplay();
		int pixels = 0;

		if(display.getOrientation() == 0)
			pixels = display.getWidth()/6;
		else
			pixels = display.getHeight()/6;
		
		
		
		Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.venues);
		ImageButton imgButton = (ImageButton) findViewById(R.id.btnVenue);
		imgButton.setImageBitmap(Bitmap.createScaledBitmap(image, pixels, pixels, false));
		imgButton.setMinimumWidth(display.getWidth()/4);
		
		
		
		
		if(tmpSession.getTitle() != null){
			tmp = (TextView)findViewById(R.id.txtTitle);
			tmp.setText(tmpSession.getTitle());
		}
		
		if(tmpSession.getDescription() != null){
			tmp = (TextView)findViewById(R.id.txtDescription);
			tmp.setText(tmpSession.getDescription());
		}
		
		if(tmpSession.getStartTime() != null){
			tmp = (TextView)findViewById(R.id.txtDate);
			tmp.setText(tmpSession.getStartTime() + "-" + tmpSession.getEndTime());
		}
		
		if(tmpSession.getRoom() != null){
			tmp = (TextView)findViewById(R.id.txtRoom);
			tmp.setText(tmpSession.getRoom());
		}
		
		
	}
	
	
	public void onVenueClick(View v){
		Log.i(TAG, "onVenueClick id " + tmpSession.getVenueId());
		
		
		Intent intent = new Intent(this, VenueMapActivity.class);
		intent.putExtra("venueId", tmpSession.getVenueId());
		intent.putExtra("conferenceId", tmpSession.getConferenceId());
		//intent.putExtra("lat", Double.parseDouble(tmpVenue.getLat()));
		//intent.putExtra("lon", Double.parseDouble(tmpVenue.getLon()));
		intent.putExtra("zoom", Integer.parseInt(this.getString(R.string.zoomclose)));
		
		//intent.setData(Uri.parse("geo:" + tmpConference.getLat() + "," + tmpConference.getLon()));
		intent.setAction(Intent.ACTION_VIEW);
		startActivity(intent);
	}
	

}
